<template>
	<view>
		<!-- tab -->
		<view class="ogzTab" :class="isHasFixedFlag ? 'hasFixed' : ''">
			<view class="tabItem posRel"
				:class="[ogzIndex == index ? 'active' : '']"
				v-for="(item,index) in ogzTab"
				:key="index"
				@tap="switchTab(index)"
			>{{item}}<view class="lineView"></view><view class="bgView"></view></view>
		</view>
		<!-- tabCon -->
		<view class="tabCon">
			<!-- 简介 -->
			<ogz-profile v-if="ogzIndex == 0" 
				:list="list" 
				:albumList="albumList" 
				:fwRangeArr="fwRangeArr" 
				@goCurrPos="goCurrPos" 
				@makePhoneCall="makePhoneCall" 
				@goGroupService="goGroupService" 
				@goFocus="goFocus"
				@previewImage="previewImage"
				@goOgzMall="goOgzMall"
			>
			</ogz-profile>
			<!-- 咨询师list -->
			<zxs-list 
				 v-if="ogzIndex == 1"
				:zxsList="teaList" 
				:loading="loading_tea" 
				:isHasDataFlag="isHasDataFlag_tea"
				 @goZxsDet="goZxsDet"
			></zxs-list>
		</view>
	</view>
</template>

<script>
	import OgzProfile from './components/OgzProfile'
	import ZxsList from '../../index/components/ZxsList'
	import { getOrgProfile,addOrUpOrgGz,getOrgTeacherList } from '@/api/ogz/index'
	export default {
		components:{
			OgzProfile,
			ZxsList,
		},
		data(){
			return{
				currPage:'ogzDetPage',
				ogzTab:['机构简介','咨询师'],
				ogzIndex:0,
				proList:[],
				isHasDataFlag:true,
				loading:false,
				nowPage:1,
				currTypeId:'',
				ogzId:'',
				albumList : [],
				list:{},
				fwRangeArr:[],
				nowPage_tea:1,
				loading_tea:false,
				teaList:[],
				isHasDataFlag_tea:null,
				isHasFixedFlag:false,
				currJumpPage:'',
				setFocFlag:false
			}
		},
		onLoad(options){
			// /org/getOrgProfile
			this.ogzId = options.ogzId;
			this.currJumpPage = options.currJumpPage == undefined ? '' : options.currJumpPage;//ogzFocPage 我的关注机构进来
			this.getOgzDetail();
		},
		onUnload(){
			if(this.currJumpPage == 'ogzFocPage' && this.setFocFlag){
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2];
				prevPage.$vm.isRefreshFlag = true;
			}
		},
		methods:{
			goFocus(){
				if(uni.getStorageSync('userIdPss')){
					var field = {orgId:this.ogzId};
					addOrUpOrgGz(field).then(res=>{
						if(this.list.gzTag == 1){
							this.list.gzTag = 0;
						}else if(this.list.gzTag == 0){
							this.list.gzTag = 1;
						}
						this.setFocFlag = true;
					}).catch(err=>{
						console.log(err)
					});
				}else{
					this.util.comNavigateToLogin('userFix');
				}
			},
			goCurrPos(){
				var lon = this.list.lon,
					lat = this.list.lat,
					ogzName = this.list.ogzName;
				this.util.openMapNaviagtion(lon,lat,ogzName)
			},
			makePhoneCall(phoneNum){
				uni.makePhoneCall({
					phoneNumber:phoneNum
				})
			},
			goGroupService(){
				uni.navigateTo({
					url:'../groupService/groupService?ogzId=' + this.ogzId
				})
			},
			previewImage(index){
				var current = this.albumList[index];
				uni.previewImage({
					current: current,
					urls: this.albumList
				})
			},
			getOgzDetail(){
				var lon = uni.getStorageSync('longitude') == '' ? 0 : uni.getStorageSync('longitude'),
					lat = uni.getStorageSync('latitude') == '' ? 0 : uni.getStorageSync('latitude');
				var field = { id:this.ogzId,lon:lon,lat:lat };
				uni.showLoading({ title: '加载中...', mask: true });
				getOrgProfile(field).then(res=>{
					this.list = res.data.datas;
					this.fwRangeArr = this.list.sysRange.split(',');
					let photoList = this.list.pList;
					if(photoList.length > 0){
						for(let i in photoList) {
							if(photoList[i].zlImg.startsWith('http')){
								this.albumList.push(photoList[i].zlImg);
							}else{
								this.albumList.push(this.cloudUrl + photoList[i].zlImg);
							}
						}
					}else{
						let tmpHeadImg = this.getCloudFilePath(this.list.ogzImg);
						this.albumList.push(tmpHeadImg)
					}
				}).catch(err=>{
					console.log(err)
				});
			},
			loadTypeProList(){
				let { nowPage,proList } = this;
				this.loading = true;
				var field = {ogzId:this.ogzId,typeId:this.currTypeId,page:this.nowPage,limit:this.limit}
				loadProListyByType(field).then(res=>{ 
					nowPage += 1;
					proList.push( ...res.data.datas );
					this.proList = proList;
					this.nowPage = nowPage;
					this.loading = false;
					this.isHasDataFlag = true;
				}).catch((err)=>{
					//console.log(err)
					this.loading = false;
					this.isHasDataFlag=false;
				})
			},
			//分页获取机构下咨询师list
			getOgzZxsList(){
				let { nowPage_tea,teaList } = this;
				this.loading_tea = true;
				var field = {orgId:this.ogzId,page:this.nowPage_tea,limit:this.limit}
				//console.log(field)
				getOrgTeacherList(field).then(res=>{
					//console.log(res)
					nowPage_tea += 1;
					teaList.push( ...res.data.datas );
					this.teaList = teaList;
					this.nowPage_tea = nowPage_tea;
					this.loading_tea = false;
					this.isHasDataFlag_tea = true;
				}).catch(err=>{
					this.loading_tea = false;
					this.isHasDataFlag_tea=false;
				});
			},
			switchTab(index){
				this.ogzIndex = index;
				if(this.ogzIndex == 0){
					//this.getOgzDetail();
				}else if(this.ogzIndex == 1){//机构咨询师
					this.initParams_tea();
				}/*else{
					this.initParams_pro();
				}*/
			},
			initParams_tea(){
				this.nowPage_tea = 1;
				this.loading_tea = false;
				this.teaList = [];
				this.getOgzZxsList();
			},
			initParams_pro(){
				this.nowPage = 1;
				this.loading = false;
				this.proList = [];
				this.loadTypeProList();
			},
			//去查看咨询师详情
			goZxsDet(id){
				uni.navigateTo({
					url:'../zxsDet/zxsDet?userId=' + id
				})
			}
		}
	}
</script>

<style lang='scss'>
	page{
		margin-top: 90rpx;
	}
	.ogzTab{
		height: 90rpx;
		display: flex;
		width: 100%;
		padding: 0;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 100;
		background: #fff;
		.tabItem{
			width: 50%;
			/* padding: 0 50rpx; */
			height: 100%;
			line-height: 90rpx;
			text-align: center;
			font-size: $font-size30;
			color: $pss-text-colora;
			.bgView{
				width: 30%;
				height: 16rpx;
				background: #ffeed2;
				filter: blur(2px);
				position: absolute;
				left: 35%;
				top: 40rpx;
				z-index: -1;
				display: none;
			}
			.lineView{
				width: 8%;
				height: 10rpx;
				border-radius: 50rpx;
				background: $pss-linear-gradient;
				position: absolute;
				left:46%;
				bottom: 10rpx;
				display: none;
			}
			&.active{
				font-size: $font-size32;
				color: $pss-text-color3;
				font-weight: bold;
				.bgView,
				.lineView{
					display: block;
				}
			}
		}
	}
</style>